import time

import pyautogui
# import wxauto
import keyboard
import pyperclip
#import opencv-python

DEBUG = 1


def debug_print(*p):
    if DEBUG:
        print(*p)


def click_picture(picture_path):
    button_pos = pyautogui.locateOnScreen(picture_path, confidence=0.9)  # ,confidence=1,locateOnScreen
    if button_pos is None:
        debug_print('没有找到按键')
        return False
    else:
        debug_print('找到按键')
        button_center = pyautogui.center(button_pos)
        pyautogui.click(button_center)
        return True


def find_button(button_pos, button_name):
    if button_pos is None:
        print('没有找到按键', button_name)
    else:
        print('找到按键', button_name)


# 有信息过来
'''def ComeXinXi():
    find_msg = click_picture('huilong.png')
    time.sleep(1)
    if find_msg:
        #pyautogui.click(find_msg)
        pyautogui.moveTo(find_msg)
        return True
    else:
        return False'''


# 拷贝信息
def copyXinxi():
    x, y = click_picture('./img/copyflag.png')
    debug_print('ready copy')
    # debug_print(button_center)
    debug_print('copy work')
    x += 20
    y -= 60
    # pyautogui.moveTo(x,y)
    pyautogui.rightClick(x, y)

    # 开始复制聊天记录

    button_center = click_picture('./img/cp.png')
    pyautogui.click(button_center)
    text = pyperclip.paste()
    debug_print(text)
    sendXinXi(text)

    # test =pyperclip.copy()
    # print(test)
    return True


def sendXinXi(text):
    x, y = click_picture('./img/copyflag.png')
    y += 60
    pyautogui.click(x, y)
    pyautogui.hotkey('ctrl', 'v')  # 使用热键才可以写入中文
    # pyautogui.write('?')
    pyautogui.press('enter')


# ====================   start   ==========

'''while True:

    doSend = ComeXinXi()'''
    #if doSend:
       # copyXinxi()
        # sendXinXi()
